package com.ruoyi.system.domain;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.config.RuoYiConfig;
import lombok.Data;

import java.io.File;
import java.util.Date;

@TableName("sys_file_log")
@Data
public class SysFileLog {
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String fileName;
    private String fileType;
    private Long fileSize;
    private String filePath;
    @TableField(exist = false)
    private String fileUrl;
    private String fileAbsolutePath;
    private Date createTime;
    private Boolean success = false;
    @TableField(exist = false)
    private File file;
    public File getFile(){
        if (file == null){
            if (StrUtil.isNotEmpty(fileAbsolutePath)){
                file  = new File(fileAbsolutePath);
            }else{
                String uploadPath = RuoYiConfig.getUploadPath();
                String path = uploadPath+filePath;
                file = new File(path);
            }
            if (file.exists()){
                return file;
            }else{
                return null;
            }
        }
        return file;
    }
}
